package com.linkoog.devtools.http.parser.spring.common;

import com.linkoog.devtools.http.common.HttpMethod;

import java.util.Arrays;
import java.util.List;

public class SpringConstants {

    public static final String CONTROLLER = "org.springframework.stereotype.Controller";
    public static final String REST_CONTROLLER = "org.springframework.web.bind.annotation.RestController";

    public static final String REQUEST_MAPPING = "org.springframework.web.bind.annotation.RequestMapping";

    public static final String GET_MAPPING = "org.springframework.web.bind.annotation.GetMapping";
    public static final String POST_MAPPING = "org.springframework.web.bind.annotation.PostMapping";
    public static final String PUT_MAPPING = "org.springframework.web.bind.annotation.PutMapping";
    public static final String DELETE_MAPPING = "org.springframework.web.bind.annotation.DeleteMapping";
    public static final String PATCH_MAPPING = "org.springframework.web.bind.annotation.PatchMapping";

    public static final String REQUEST_PARAM = "org.springframework.web.bind.annotation.RequestParam";
    public static final String PATH_VARIABLE = "org.springframework.web.bind.annotation.PathVariable";
    public static final String REQUEST_HEADER = "org.springframework.web.bind.annotation.RequestHeader";
    public static final String REQUEST_BODY = "org.springframework.web.bind.annotation.RequestBody";

    public final static List<String> CLASS_ANNOTATION_LIST = Arrays.asList(CONTROLLER, REST_CONTROLLER);
    public final static List<String> METHOD_ANNOTATION_LIST = Arrays.asList(REQUEST_MAPPING, GET_MAPPING,POST_MAPPING,PUT_MAPPING,DELETE_MAPPING,PATCH_MAPPING);


    public enum MappingEnum {

        GET_MAPPING(SpringConstants.GET_MAPPING, HttpMethod.GET),
        POST_MAPPING(SpringConstants.POST_MAPPING, HttpMethod.POST),
        PUT_MAPPING(SpringConstants.PUT_MAPPING, HttpMethod.PUT),
        DELETE_MAPPING(SpringConstants.DELETE_MAPPING, HttpMethod.DELETE),
        PATCH_MAPPING(SpringConstants.PATCH_MAPPING, HttpMethod.PATCH),
        ;
        private String qualifiedName;

        private HttpMethod httpMethod;

        MappingEnum(String qualifiedName,HttpMethod httpMethod) {
            this.qualifiedName = qualifiedName;
            this.httpMethod = httpMethod;
        }

        public static MappingEnum valueOfQualifiedName(String qualifiedName){
            for (MappingEnum mappingAnnotation : MappingEnum.values()) {
                if (mappingAnnotation.getQualifiedName().equals(qualifiedName)){
                    return mappingAnnotation;
                }
            }
            return null;
        }

        public String getQualifiedName() {
            return qualifiedName;
        }

        public HttpMethod getHttpMethod() {
            return httpMethod;
        }
    }


}
